using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using BlawkayMobileLibrary;

namespace Bounce
{
    public class ManyBalls : GameType
    {
        public ManyBalls(GamePage oPage)
            : base(oPage)
        { }

        #region Screen Methods

        public override void Initialize(ContentManager oContentManager, GraphicsDevice oDevice)
        {
            base.Initialize(oContentManager, oDevice);

            Resolution = new Vector2(oDevice.Viewport.Width, oDevice.Viewport.Height);

            Texture2D texture_Basketball = oContentManager.Load<Texture2D>("Circle");
            Texture2D texture_Rim = oContentManager.Load<Texture2D>("Circle");

            for (int i = 0; i < 15; i++)
            {
                int row = i % 3;
                int column = i % 5;
                Vector2 vPosition = new Vector2(50 + (row * 100) + (column * 3), 300 + (column * 100));

                BasketBalls.Add(new Basketball(texture_Basketball, vPosition, 30.0f, 2.0f));
            }

            Goals.Add(new Goal(new Vector2(200, 200), texture_Rim));
        }

        #endregion

        protected override void CheckCollisions()
        {
            CheckCollisions_Balls();
            CheckCollisions_Goals();
            CheckCollisions_Walls();
        }

        protected override void DrawGameType()
        {
        }

        protected override void Input()
        {
            TouchCollection oCollection = TouchPanel.GetState();
            foreach (Basketball oBall in BasketBalls)
            {
                foreach (TouchLocation location in oCollection)
                {
                    if (Circle.HasCollisionBetween(oBall.Position, oBall.Radius, location.Position, 40.0f))
                    {
                        oBall.UpdateVelocity(oBall.Velocity.X, -20f);
                    }
                }
            }
        }

    }
}
